package com.IC.base.controller;

import IC.common.core.domain.R;
import com.IC.base.service.UserService;
import com.IC.domain.SysOrg;
import com.IC.domain.User;
import com.IC.domain.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：xiawenze
 * @Package：com.IC.base.controller
 * @Project：smart2
 * @name：UserController
 * @Date：2024/7/31 15:02
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("findUserList")
    public R findUserList(@RequestParam(name = "name" ,required = false) String name, @RequestParam(name = "uname" ,required = false) String uname, @RequestParam(name = "roleName" ,required = false) String roleName, @RequestParam(name = "orgId" ,required = false) Integer orgId){
        List<UserVO> userlist=userService.findUserList(name,uname,roleName,orgId);
        return R.ok(userlist);
    }

    @PostMapping("addUser")
    public R addUser(@RequestBody User user){
        userService.addUser(user);
        return R.ok();
    }

    @GetMapping("findSelectOrg")
    public R findSelectOrg(){
        List<UserVO> sysOrgs=userService.findSelectOrg();
        return R.ok(sysOrgs);
    }

    @GetMapping("findSelectOrgById")
    public R findSelectOrgById(@RequestParam Integer id){
        List<UserVO> sysOrgs=userService.findSelectOrgById(id);
        return R.ok(sysOrgs);
    }

    @PostMapping("updateUser")
    public R updateUser(@RequestBody User user){
        userService.updateUser(user);
        return R.ok();
    }

    @GetMapping("delete/{id}")
    public R delete(@PathVariable("id") Integer id){
        userService.delete(id);
        return R.ok();
    }

    @GetMapping("updateUpwd")
    public R updateUpwd(@RequestParam("id") Integer id,@RequestParam("upwd") String upwd){
        userService.updateUpwd(id,upwd);
        return R.ok();
    }

    @GetMapping("updateStatue/{id}")
    public R updateStatue(@PathVariable Integer id){
        userService.updateStatue(id);
        return R.ok();
    }


    @GetMapping("getInfo")
    public void getInfo(){
        System.out.println("ahahha");
    }
    @GetMapping("forInfo")
    public void forInfo(){
        System.out.println("哈哈哈");
        for (int i = 0; i < 10; i++) {
            this.getInfo();
        }

    }



}
